package sample.config;

import brave.ScopedSpan;
import brave.Tracing;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * Created on 2020/7/1
 */
@Aspect
@Component
public class TraceAspect {
	@Autowired
	private Tracing tracing;

	@Around("execution(* sample.service.LocalService.*(..))")
	public Object around(ProceedingJoinPoint point) throws Throwable {
		Object result = null;
		String method = point.getSignature().getName();
		ScopedSpan span = tracing.tracer().startScopedSpan(method);
		try {
			result = point.proceed();
		} finally {
			span.finish();
		}
		return result;
	}
}
